/**
 * Created by Administrator on 2017/5/26 0026.
 */

function test(){
    $('body').css('display', 'block');
}
//请先注册按钮
$(function(){
    $("#firstreg").on("click",function(){
        window.location.href="reg.html";
    })


    //服务器登录验证

    $("#btn").on("click",function(){


        //点击登录，验证码验证
        if($(".yan").val()==$(".yimg").text()){
            $.ajax({
                url:"./server/login.php",
                type:"post",
                data:{
                    "loginname":$(".uname").val(),
                    "loginpwd":$(".upwd").val()
                },
                success:function(res){
                    var obj=JSON.parse(res);
                    console.log(obj);
                    if(obj.status==1){
                        alert("登录成功");
                        window.location.href="index.html";

                    }else {
                        alert("用户名或密码错误，请重新登录")
                        window.location.href="login.html";
                    }
                }
            })
        }else {
            alert("验证码错误！")
        }
    })
})


$(function(){

    $(".yimg").on("click",function(){
        $(".yimg").css({
            color:"rgb("+getColor()+","+getColor()+","+getColor()+")"
            ,fontSize:"22px",fontWeight:"900"}).text(""+getRom()+""+getRom()+""+getRom()+""+getRom()+"")

    })


    //随机生成验证码
    function getRom(){
        var onum=parseInt(Math.random()*123);
        if(onum>=97&&onum<=122){
            //
            // return String.fromCharCode(65+onum)
        }else {
            return getRom()
        }
        return String.fromCharCode(onum)
    }

    //随机生成验证码颜色
    function  getColor(){
        var clor=parseInt(Math.random()*256);
        return clor;
    }




})